#include <poll.h>
#include <unistd.h>
#include <iostream>
#include<stdio.h>
#include <stdlib.h>

int main()
{
    struct pollfd poll_fd;
    poll_fd.fd = 0;
    poll_fd.events = POLLIN;

    while (true)
    {
        int ret = poll(&poll_fd, 1, 1000);
        if (ret < 0)
        {
            perror("poll");
            exit(2);
        }
        else if (ret == 0)
        {
            std::cout << "time out , try again" << std::endl;
        }
        else
        {
            if (poll_fd.revents & POLLIN)
            {
                char buffer[1024];
                int n = read(poll_fd.fd, buffer, sizeof(buffer) - 1);
                buffer[n] = 0;
                std::cout << "stdin:# " << buffer << std::endl;
            }
        }
    }
    return 0;
}